package project3;

/**
 * @author oldlpiu
 * @since 1.0
 */
public class PC {
    private String brand;
    private boolean start=false;
    private boolean format=false;
    private  long capbility;//磁盘容量
    private Disk[] disks;
    private OS os;//当前安装的操作系统信息

    public PC(String brand) {
        this.brand = brand;
    }

    public PC(String brand, long capbility) {
        this.brand = brand;
        this.capbility = capbility;
    }

    public void start(){
        if(start)
        {
            System.out.println("已经启动！");
            return;
        }
        System.out.println("电脑"+brand+"启动成功!");
        start=true;
    }
    //格式化整个磁盘
    public void format(int size,String[]label,long[]cap){
        //...
        //if(size<1) throw new
        //if(format)
        long total=this.capbility;
        for(long t:cap)
            total-=t;
        if(total<0)
            throw new RuntimeException("各个磁盘的容量超总容量"+(-total)+"兆");

        this.disks=new Disk[size];
        for(int i=0;i<size;i++){
            this.disks[i]=new Disk(label[i],cap[i]);
        }
        format=true;
    }
    //根据盘符，找到磁盘对象
    private Disk find(String label){
        for(Disk t:disks){
            if(t.getLabel().equals(label))
                return t;
        }
        return null;
    }
    //安装软件到某个磁盘
    public boolean install(Soft soft,String label){
        Disk d=find(label);
        if(d==null)return false;
        return d.install(soft);
    }
    //安装操作系统到某个磁盘
    public boolean install(OS soft,String label){
        Disk d=find(label);
        if(d==null)return false;
        boolean b= d.install(soft);
        if(b){
            this.os=soft;
        }
        return b;
    }
    public void show(){
        System.out.println("电脑是"+brand+",容量是"+this.capbility+"M");
        System.out.println(os==null?"当前没有安装操作系统":"当前安装了"+os.getName());
        for(int i=0;disks!=null&&i<disks.length;i++){
            disks[i].show();
        }
    }
    //判断操作系统是否安装好
    public boolean isOsInstalled(){
        return os!=null;
    }
    public String getBrand() {
        return brand;
    }

    public void setBrand(String brand) {
        this.brand = brand;
    }

    public boolean isStart() {
        return start;
    }

//    public void setStart(boolean start) {
//        this.start = start;
//    }

    public boolean isFormat() {
        return format;
    }

//    public void setFormat(boolean format) {
//        this.format = format;
//    }
}
